package com.orhon.smartcampus.modules.systemctl.entity;

import java.util.Date;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import org.hibernate.annotations.NotFound;
import org.hibernate.annotations.NotFoundAction;
import org.hibernate.annotations.Where;

import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
@Setter
@Getter
@EqualsAndHashCode
@Entity
@Table(name = "systemctl_org_duties", schema = "smartcloud", catalog = "")
public class OrgDuties {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id", nullable = false)
    private Long id;
    @Column(name = "duties_name", nullable = true)
    private String dutiesName;
    @Column(name = "duties_order", nullable = true)
    private Integer dutiesOrder;
    @Column(name = "level", nullable = true)
    private Integer level;
    @Column(name = "created_at", nullable = false)
    private Date createdAt;
    @Column(name = "updated_at", nullable = true)
    private Date updatedAt;
    @Column(name = "deleted_at", nullable = true)
    private Date deletedAt;

    @ManyToOne
    @JoinColumn(name = "parent_id", referencedColumnName = "id")
    @Where(clause = "ISNULL(deleted_at)")
    @NotFound(action=NotFoundAction.IGNORE)
    private OrgDuties systemctlOrgDutiesByParentId;


    //部门
    @ManyToMany(cascade = CascadeType.ALL,  fetch = FetchType.LAZY)
    @Where(clause = "ISNULL(deleted_at)")
    @NotFound(action=NotFoundAction.IGNORE)
    @JoinTable(
            name = "systemctl_org_department_duty_relation",
            joinColumns = { @JoinColumn(name = "duty_id")},
            inverseJoinColumns = { @JoinColumn(name = "department_id")}
    )
    private List<OrgDepartments> departments;
}
